package com.ostraffel.recallvocabularybackend.TempTest;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.ostraffel.recallvocabularybackend.DTO.ApplicationDictDTO;
import com.ostraffel.recallvocabularybackend.DTO.UserConfig;
import com.ostraffel.recallvocabularybackend.DTO.UserConfigDetailed;
import com.ostraffel.recallvocabularybackend.DTO.Word;
import com.ostraffel.recallvocabularybackend.service.serviceutils.Utils;

@Service
public class TempTest {

    @Autowired
    private Utils utils;

    public List<Word> CreateWords(){
        List<Word> words = new ArrayList<>();
        words.add(CreateWord());
        words.add(CreateWord());
        words.add(CreateWord());
        return words;
    }

    public Word CreateWord(){
        Word word = new Word();
        word.setSpell("test");
        word.setIpa("test");
        word.setExplication("test");
        word.setProficiency(0);
        word.setLastDate(new java.sql.Date(System.currentTimeMillis()));
        word.setUserId("test");
        return word;
    }
    
    public UserConfig SearchUserConfig(String userId) {
        UserConfigDetailed userConfigDetailed = new UserConfigDetailed();
        userConfigDetailed.UserConfigDetailed_Test();
        UserConfig userconfig = new UserConfig(userConfigDetailed);
        return userconfig;
    }

    final String DIR_PATH = "D:/test/recall-vocabulary-backend/data";
    public void PutListInDir(MultipartFile file, String dictionaryName)  throws IOException {
        // 创建目录
        Path uploadPath = Paths.get(DIR_PATH);
        if (!Files.exists(uploadPath)) {
            Files.createDirectories(uploadPath);
        }
        Path filePath = uploadPath.resolve(dictionaryName);
        // 保存文件（如果已存在则替换）
        Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
    }

    // @Autowired
    // private Utils utils;

    public void ApplicationService(String userId, String dictName) throws IOException {
        utils.GnerateUserTable(userId, dictName);
    }

    public void TransportWordsService(){
        utils.TransportWordsMapper();
    }
    public void GnerateUserTableService(ApplicationDictDTO applicationDictDTO){
        utils.GnerateUserTable(applicationDictDTO.getUserId(), applicationDictDTO.getDictName());
    }

    public void AddUserService(UserConfigDetailed userConfigDetailed) {
        utils.AddUserMapper(userConfigDetailed);
    }
}
